import pytest
import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# from core.page.login_page import LoginPage  # 避免循环导入


# ------------------------------
# 1. 全局driver fixture：整个测试会话复用一个驱动
# ------------------------------
# @pytest.fixture(scope="session")
# def driver():
#     # 初始化Chrome驱动（自动管理驱动版本）
#     chrome_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'
#     chrome_sevice = Service(executable_path=chrome_path)
#
#     chrome_options = webdriver.ChromeOptions()
#     chrome_options.add_argument("--window-size=1920,1080")
#
#     driver = webdriver.Chrome(service=chrome_sevice, options=chrome_options)
#     driver.maximize_window()
#
#     yield driver  # 提供driver给测试用例
#     # 测试结束后清理：关闭浏览器
#     driver.quit()
@pytest.fixture(scope="session")
def driver():
    """全局driver fixture"""
    chrome_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'
    chrome_sevice = Service(executable_path=chrome_path)
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--window-size=1920,1080")

    driver = webdriver.Chrome(service=chrome_sevice, options=chrome_options)
    driver.maximize_window()

    yield driver
    driver.quit()


# test_data = {"https://www.chiphell.com", "https://www.baidu.com"}
#
#
# @pytest.fixture(scope="function", params=test_data)
# def url(request):
#     return request.param


# ------------------------------
# 2. 登录页fixture：预初始化登录页，测试用例直接使用
# ------------------------------



# @pytest.fixture(scope="function")
# def login_page(driver, request):
#     """接收动态URL的登录页fixture"""
#     # 通过request.param获取测试用例传递的URL
#     target_url = request.param  # 核心：动态获取当前用例的URL
#     login_page = LoginPage(driver)
#     login_page.go_to_url(target_url)  # 访问当前用例的专属URL
#     return login_page
#     # print(f"{url}")
#     # login_page = LoginPage(driver)
#     # login_page.go_to_url(url)  # 跳转到登录页
#     # return login_page
